using System;
using Microsoft.Xna.Framework;

namespace SpriteAnimations.Graphics.Animations
{
    class TimedAnimation : SpriteAnimation
    {
        //
        // Fields
        //
        private SpriteAnimation animation;
        private TimeSpan timeLeft;

        //
        // Constructors
        //
        public TimedAnimation(TimeSpan length, SpriteAnimation animation)
        {
            this.animation = animation;
            this.timeLeft = length;
        }

        //
        // Virtual Methods
        //
        public override void Animate(TimeSpan gameTime, SpriteParameters animatedParameters)
        {
            timeLeft.Subtract(gameTime);

            if (timeLeft.TotalSeconds < 0)
                base.IsFinished = true;
            else
                animation.Animate(gameTime, animatedParameters);
        }
    }
}
